<!--
 * @Author: your name
 * @Date: 2020-10-26 15:29:17
 * @LastEditTime: 2020-10-31 16:00:20
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \就业班练习d:\桌面\ma-pc\test\store.html
-->
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

<!-- <script src="https://eqcn.ajz.miesnfu.com/wp-content/plugins/wp-3d-pony/live2dw/lib/L2Dwidget.min.js"></script> -->
<!-- 
<script>
    L2Dwidget.init({
        "model": {
            jsonPath: "https://unpkg.com/live2d-widget-model-koharu@1.0.5/assets/koharu.model.json",
            "scale": 1
        },
        "display": {
            "position": "left",
            "width": 150,
            "height": 300,
            "hOffset": 0,
            "vOffset": -20
        },
        "mobile": {
            "show": true,
            "scale": 0.5
        },
        "react": {
            "opacityDefault": 0.7,
            "opacityOnHover": 0.2
        }
    });
</script> -->
<script>
    const $eventBus = {
        events: {}, //------------------------------------------------------------存放事件区

        $on: function (eName, callback) {  //-------------------------------------添加事件区
            if (this.events[eName]) {
                this.events[eName].push(this.events[eName] = callback)
            } else {
                this.events[eName] = []
                this.events[eName].push(this.events[eName] = callback)
            }
        },   
        
        $emit: function (eName, params) { //--------------------------------------执行事件区
            this.events[eName].forEach((item) => {
                item(params)          //执行传进来的事件名对应的事件
            })
        }

    }
    // $eventBus.$on("事件名", callback)        //1.注册自定义事件
    // $eventBus.$emit("事件名", params)               //2.执行自定义事件 
    // 疑问:  怎么理解发布订阅的词义 注册事件就是订阅吗  

    $eventBus.$on("setName", (name) => {//注册事件
        this.userInfo.name = name
    })               

    this.$eventBus.$emit('setName', name)  //执行事件并传参
</script>

</html>